<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class My_Form_validation extends CI_Form_validation {
	public function _construct($rules = array())
	{
		parent::_construct	($rules);
	}
	function valid_date($str,$format= 'dd/mm/yyyy')
 {
        switch($format)
        {

            case 'yyyy/mm/dd':
                if(preg_match("/^(19\d\d|2\d\d\d)[\/|-](0?[1-9]|1[012])[\/|-](0?[1-9]|[12][0-9]|3[01])$/", $str,$match) && checkdate($match[2],$match[3],$match[1]))
                {
                    return TRUE;
                }
            break;
            case 'mm/dd/yyyy':
                if(preg_match("/^(0?[1-9]|1[012])[\/|-](0?[1-9]|[12][0-9]|3[01])[\/|-](19\d\d|2\d\d\d)$/", $str,$match) && checkdate($match[1],$match[2],$match[3]))
                {
                    return TRUE;
                }
            break;
            default: // 'dd/mm/yyyy'
                if(preg_match("/^(0?[1-9]|[12][0-9]|3[01])[\/|-](0?[1-9]|1[012])[\/|-](19\d\d|2\d\d\d)$/", $str,$match) && checkdate($match[2],$match[1],$match[3]))
                {
                return TRUE;
                }
            break;

        }
        return FALSE;
 } 
}
?>